package com.leetcode.LC;

import java.util.HashSet;

public class LC804 {
    public int uniqueMorseRepresentations(String[] words) {
        //使用set存储省去了比较
        HashSet<String> set = new HashSet<>();
        for (String word : words) {
            set.add(translationWord(word));
        }
        return set.size();
    }

    //单词翻译成摩斯密码
    public String translationWord(String word) {

        String[] strings = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < word.length(); i++) {
            builder.append(strings[word.charAt(i) - 'a']);
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new LC804().uniqueMorseRepresentations(new String[]{"gin", "zen", "gig", "msg"}));
        System.out.println(new LC804().translationWord("iloveyou"));
    }
}
